form='%s %s %f';
in = textscan(fid, form,'delimiter','\t','HeaderLines',1);
fclose(fid);

N=length(in{1});
cleanup=strings(N,1);
tmp=in{1};
years=zeros(N,1);
ch='()0123456789';
for i=1:N
    strtmp=tmp(i);
    strtmp=erase(strtmp,'"');
    dd=strfind(strtmp,'(');
    tmp{i}=strtmp{1}(1:(dd{1}-1));
    if length(tmp{i})>=4
       for y=2005:2030
           ind=strcmp(tmp{i}(1:4),num2str(y));
           if ind==1, years(i)=y; else end
       end
    end
   tmp{i}  = erase(tmp(i),'(NEC)');
   for j=1:length(ch)
       tmp{i}  = erase(tmp{i},ch(j));
   end
   cleanup(i)=tmp{i};
end
ind=find(years>0);
for i=1:length(ind)
    cleanup(ind(i))='All';
end

tmp=unique(cleanup);
NN=length(tmp);
ind=zeros(NN,1);
for i=1:NN
    if length(tmp{i})>1, ind(i)=1; else end
end
industrynames=tmp(ind>0.5);

for j=2:length(years)
    years(j)=max(years(j),years(j-1));
end

FirstEntry=min(find(years>0));

tmp1=in{1};
NewObs=cleanup(FirstEntry:end);
NewYears=years(FirstEntry:end);
tmpamo=in{3};
NewAmo=tmpamo(FirstEntry:end);
industrynames=unique(NewObs);
[Lia Locb]=ismember(industrynames,'');
industrynames=industrynames(Lia==0);
uniqueyears=unique(NewYears);
Ny=length(uniqueyears);
FirstYear=min(NewYears);
Ns=length(industrynames);
amo=zeros(Ns,Ny);

for i=1:length(industrynames)
    [Lia Locb]=ismember(NewObs,industrynames(i));
    for j=1:sum(Lia)
       tmpy=NewYears(Lia>0);
       Lia2=ismember(uniqueyears,tmpy);
       if sum(Lia2)==sum(Lia)
            amo(i,Lia2)=NewAmo(Lia);
       else end
    end
    
end

out.dat=amo;
out.industry=industrynames;
out.years=uniqueyears;









